
import { t } from '@src/locales'
import { openAccurateTab } from '@src/util/platform'
import { PageRoutesTypeEnum } from 'pub-bbx-global/pageType/dist/enum/PageRoutesEnum'

export default {
  name: 'biz-call-center-record',
  props: {
    record: {
      type: Object,
      default: () => {}
    }
  },
  methods: {
    detail(){
      const {id,phone} =this.record.content
      if(!id) return 
      openAccurateTab({
        type: PageRoutesTypeEnum.PageCallcenterView,
        key: id,
        params: `id=${id}&phone=${phone}`,
        fromId: 'M_CASE'
      })
    },
    // 坐席呼出 接听和未接
    renderAgentCallsOut(record){
      let { userName, content, staffId, userId, action } = record;
      const callState = content.callState == '接听' ? 'answer' : 'notConnected'
      return (
        <i18n path={`common.record.task['${action}']`} tag="h5">
          <span place="agentNo">{content.agentNo}</span>
          <span place="operator">
            <recordUserName userName={userName} staffId={staffId} userId={userId} />
          </span>
          <span place="linkmanName">{content.linkmanName}</span>
          <span place="phone">{content.phone}</span>
          <span place="callState">{t(`common.record.task['${callState}']`)}</span>
          <span class='link-text' place="id" onClick={this.detail} >{content.recordId}</span>
        </i18n>
      )
    },
    renderCustomerCallIn_answer(record){
      let { userName, content, staffId, userId } = record;
      return (
        <i18n path={`common.record.task.customerCallIn_answer`} tag="h5">
          <span place="linkmanName">{content.linkmanName}</span>
          <span place="phone">{content.phone}</span>
          <span place="agentNo">{content.agentNo}</span>
          <span place="operator">
            <recordUserName userName={userName} staffId={staffId} userId={userId} />
          </span>
          <span class='link-text' place="id" onClick={this.detail} >{content.recordId}</span>
        </i18n>
      )
    },
    // 客户呼入 接听
    renderCustomerCallIn_notConnected(record){
      let { content } = record;
      return (
        <i18n path={`common.record.task.customerCallIn_notConnected`} tag="h5">
          <span place="linkmanName">{content.linkmanName}</span>
          <span place="phone">{content.phone}</span>
          <span class='link-text' place="id" onClick={this.detail} >{content.recordId}</span>
        </i18n>
      )
    }
  },
  // 客户呼入 未接
  render(h) {
    let { content, action } = this.record;
    const callState = content.callState;
    if(action == '坐席呼出') return this.renderAgentCallsOut(this.record);
    if(action == '客户呼入'){
      if(callState == '接听') return this.renderCustomerCallIn_answer(this.record);
      if(callState == '未接') return this.renderCustomerCallIn_notConnected(this.record);
    }
  }
}